<?php

/**
 * This is the model class for table "{{key_link}}".
 *
 * The followings are the available columns in table '{{key_link}}':
 * @property integer $zkl_id
 * @property string $zkl_title
 * @property string $zkl_url
 * @property string $zkl_target
 * @property integer $zkl_num
 * @property integer $zkl_listorder
 * @property integer $inputtime
 */
class KeyLink extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return KeyLink the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{key_link}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zkl_title, zkl_url', 'required'),
			array('zkl_num, zkl_listorder, inputtime', 'numerical', 'integerOnly'=>true),
			array('zkl_title', 'length', 'max'=>100),
			array('zkl_url', 'length', 'max'=>255),
			array('zkl_target', 'length', 'max'=>6),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zkl_id, zkl_title, zkl_url, zkl_target, zkl_num, zkl_listorder, inputtime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zkl_id' => '关键词ID',
			'zkl_title' => '关链词',
			'zkl_url' => '链接地址',
			'zkl_target' => '打开方式',
			'zkl_num' => '替换次数',
			'zkl_listorder' => '排序',
			'inputtime' => '创建时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zkl_id',$this->zkl_id);
		$criteria->compare('zkl_title',$this->zkl_title,true);
		$criteria->compare('zkl_url',$this->zkl_url,true);
		$criteria->compare('zkl_target',$this->zkl_target,true);
		$criteria->compare('zkl_num',$this->zkl_num);
		$criteria->compare('zkl_listorder',$this->zkl_listorder);
		$criteria->compare('inputtime',$this->inputtime);

		$criteria->order = " inputtime DESC ";//默认为时间倒序
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}